import {assert} from "chai"
import Dictionary from "../../../src/js/class/dictionary"

describe('class Dictionary', () => {
  const dict = new Dictionary()
  dict.set('火', '有温度，有亮度')
  describe('#hasKey()', () => {
    it(`hasKey('火') => true`, () => {
      assert.equal(dict.hasKey('火'), true)
    })
    it(`hasKey('水') => false`, () => {
      assert.equal(dict.hasKey('水'), false)
    })
  })

  describe('#get()', () => {
    it(`get('火') => 有温度，有亮度`, () => {
      assert.equal(dict.get('火'), '有温度，有亮度')
    })
    it('get(`水`) => undefined', () => {
      assert.equal(dict.get('水'), undefined)
    })
  })

  describe('#set()', () => {
    it(`set('水','透明，由氧气和氢气组成')`, () => {
      dict.set('水', '透明，由氧气和氢气组成')
      assert.equal(dict.get('水'), '透明，由氧气和氢气组成')
    })
    it(`set('金','一般指金属，有光泽，育延展性')`, () => {
      dict.set('金', '一般指金属，有光泽，育延展性')
      assert.equal(dict.get('金'), '一般指金属，有光泽，育延展性')
    })
  })

  describe('#length', () => {
    console.log(`length`, dict.length)
    it('length === 3', () => {
      assert.equal(dict.length, 3)
    })
    it('length === 4', () => {
      dict.set('木', '树木，木材')
      assert.equal(dict.length, 4)
    })
  })

  describe('#remove', () => {
    it(`remove('土')`, () => {
      assert.equal(dict.remove('土'), false)
    })
    it(`remove('水')`, () => {
      assert.equal(dict.length, 4)
      assert.equal(dict.hasKey('水'), true)
      assert.equal(dict.remove('水'), true)
      assert.equal(dict.length, 3)
      assert.equal(dict.hasKey('水'), false)
    })
  })

  describe('#keys', () => {
    it('keys()', () => {
      const arr = dict.keys()
      assert.equal(arr.length, 3)
      const arrStr = [ '金', '火', '木' ]
      assert.equal(arr.every(key => {
        return arrStr.includes(key)
      }), true)
    })
  })

  describe('#values()', () => {
    it('values()', () => {
      const arr = dict.values()
      assert.equal(arr.length, 3)
      const arrStr = [ '有温度，有亮度',
        '一般指金属，有光泽，育延展性',
        '树木，木材', ]
      assert.equal(arr.every(key => {
        return arrStr.includes(key)
      }), true)
    })
  })

  describe('#entires()', () => {
    it(`entires`, () => {
      let arr = dict.entires()
      assert.equal(arr.length, 3)
      const arrStr = dict.keys()
      const arrValues = dict.values()
      assert.equal(arr.every(item => {
        return arrStr.includes(item.key)
      }), true)
      assert.equal(arr.every(item => {
        return arrValues.includes(item.value)
      }), true)
    })
  })

  describe('#forEach()', () => {
    it(`forEach`, () => {
      let count = 0
      let arrStr = dict.keys()
      dict.forEach((item) => {

        count++
        assert.equal(arrStr.includes(item.key), true)
      })
      assert.equal(count, 3)
    })

  })



  describe('#isEmpty', () => {
    it(`isEmpty`, () => {
      dict.clear()
      assert.equal(dict.isEmpty(), true)
    })
  })

  describe('#clear()', () => {
    it('clear()', () => {
      dict.clear()
      assert.equal(dict.length, 0)
    })
  })









})
